package com.tedu.egaddress1.Conreoller;

import com.tedu.egaddress1.mapper.AddressMapper;
import com.tedu.egaddress1.pojo.dto.AddressAddParam;
import com.tedu.egaddress1.pojo.entity.Address;
import com.tedu.egaddress1.pojo.vo.AddressInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @PostMapping("/add")
    public String insert(@RequestBody AddressAddParam addressAddParam){
        Address address = new Address();
        BeanUtils.copyProperties(addressAddParam,address);
        int num = addressMapper.insert(address);
        return num>0?"添加成功":"添加失败";
    }
    @GetMapping("/list")
    public List<AddressInfoVO> select(){
        List<AddressInfoVO> addressInfoVOList = addressMapper.select();
        return addressInfoVOList;
    }
    @PostMapping("/del")
    public String delete(Integer id){
        int num = addressMapper.delete(id);
        return num>0?"删除成功":"删除失败";
    }
}
